package com.xbts.screen.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.xbts.common.core.constant.ScreenConstants;
import com.xbts.common.core.enums.ConsumeTypeEnum;
import com.xbts.common.core.enums.WorkshopTypeEnum;
import com.xbts.common.core.utils.DateUtils;
import com.xbts.common.core.utils.bean.BeanUtils;
import com.xbts.common.core.web.domain.BaseHistogramResult;
import com.xbts.common.core.web.domain.BasePieChartResult;
import com.xbts.screen.domain.dto.HistogramDto;
import com.xbts.screen.domain.workshop.dto.CommonQueryDTO;
import com.xbts.screen.domain.workshop.dto.ConsumeMeterDataDTO;
import com.xbts.screen.domain.workshop.dto.RealTimeAchievementRateDTO;
import com.xbts.screen.domain.workshop.vo.*;
import com.xbts.screen.mapper.WorkshopCommonMapper;
import com.xbts.screen.service.IWorkshopCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 防焊
 */
@Service
public class WorkshopCommonServerImpl implements IWorkshopCommonService {

    @Autowired
    private WorkshopCommonMapper workshopCommonMapper;

    @DS("wecan")
    @Override
    public RealTimeAchievementRateVO realTimeAchievementRate(CommonQueryDTO dto) {
        RealTimeAchievementRateVO vo = new RealTimeAchievementRateVO();
        List<DayAchievementRateVO> vos = new ArrayList<>();
        vo.setDayAchievementRateVOs(vos);
        List<String> time = DateUtils.getCurrentMonth();
        dto.setStartTime(time.get(0));
        dto.setEndTime(time.get(1));
        List<RealTimeAchievementRateDTO> dtoList = workshopCommonMapper.realTimeAchievementRate(dto);
        Map<String, RealTimeAchievementRateDTO> dtoMap = dtoList.stream().collect(Collectors.toMap(RealTimeAchievementRateDTO::getOutputTime, v -> v));

        String target = "100";
        if(dtoList.size() > 0){
            target = dtoList.get(0).getDayGoal();
        }
        // 获取当前时间
        String now = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, new Date());
        List<String> days = DateUtils.getAllDaysOfMonth();
        boolean isAfter = false;
        for (int i = 0; i < days.size(); i++) {
            String day = days.get(i);
            DayAchievementRateVO dayAchievementRateVO = new DayAchievementRateVO();
            vos.add(dayAchievementRateVO);
            dayAchievementRateVO.setTime(day);
            dayAchievementRateVO.setTimeIsNow(false);
            RealTimeAchievementRateDTO rateDTO = dtoMap.get(day);
            if(!isAfter) {
                dayAchievementRateVO.setDayOfMonth(i + 1);
                if (rateDTO != null) {
                    dayAchievementRateVO.setTarget(Double.parseDouble(rateDTO.getDayGoal()));
                    dayAchievementRateVO.setTargetActual(Math.round(Double.parseDouble(rateDTO.getOutputArea()) * 100) / 100);
                } else {
                    dayAchievementRateVO.setTarget(Double.parseDouble(target));
                    dayAchievementRateVO.setTargetActual(0);
                }
                if (day.equals(now)) {
                    dayAchievementRateVO.setTimeIsNow(true);
                    dayAchievementRateVO.setCompletionRate(String.format("%.2f", dayAchievementRateVO.getTargetActual() * 100 / dayAchievementRateVO.getTarget()));
                    isAfter = true;
                }
            }
        }
        double monthActual = dtoList.stream().map(RealTimeAchievementRateDTO::getOutputArea).mapToDouble(Double::valueOf).sum();
        vo.setValue1(String.format("%.2f", Double.parseDouble(dtoList.get(0).getMonthGoal())));
        vo.setValue2(String.format("%.2f", monthActual));

        // 上月达成率
        List<String> lastMonth = DateUtils.getLastMonth();
        dto.setStartTime(lastMonth.get(0));
        dto.setEndTime(lastMonth.get(1));
        List<RealTimeAchievementRateDTO> lastMonthList = workshopCommonMapper.realTimeAchievementRate(dto);
        double lastMonthTarget = Double.parseDouble(lastMonthList.get(0).getMonthGoal());
        double lastMonthActual = lastMonthList.stream().map(RealTimeAchievementRateDTO::getOutputArea).mapToDouble(Double::valueOf).sum();
        vo.setValue3(String.format("%.2f", lastMonthTarget > 0 ? (lastMonthActual / lastMonthTarget) * 100 : 100));
        return vo;
    }

    @DS("wecan")
    @Override
    public BaseHistogramResult tenDaysAchievementRate(CommonQueryDTO dto) {
        List<String> time = DateUtils.getLastTenDayRange();
        dto.setStartTime(time.get(0));
        dto.setEndTime(time.get(1));
        BaseHistogramResult result = new BaseHistogramResult();
        List<String> targets = new ArrayList<>();
        List<String> actuals = new ArrayList<>();
        result.setTarget(targets);
        result.setActual(actuals);
        List<RealTimeAchievementRateDTO> dtoList = workshopCommonMapper.realTimeAchievementRate(dto);
        String target = "100";
        if(dtoList.size() > 0){
            target = dtoList.get(0).getDayGoal();
        }
        List<String> axis = DateUtils.getLastTenDays();
        result.setXAxis(axis);
        try {
            for (int i = 0; i < axis.size(); i++) {
                String s = axis.get(i);
                targets.add(i, target);
                actuals.add(i, "0");
                for (RealTimeAchievementRateDTO rateDTO : dtoList) {
                    String timeStr = DateUtils.parseDateToStr(DateUtils.MM_DD, DateUtils.parseDate(rateDTO.getOutputTime(), DateUtils.YYYY_MM_DD));
                    if (s.equals(timeStr)) {
                        targets.set(i, String.format("%.2f",Double.parseDouble(rateDTO.getDayGoal())));
                        actuals.set(i, String.format("%.2f",Double.parseDouble(rateDTO.getOutputArea())));
                        break;
                    }
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return result;
    }

    @DS("wecan")
    @Override
    public StatisticalRateGroupByTimeVO achievementRateGroupByTimeType(CommonQueryDTO dto) {
        StatisticalRateGroupByTimeVO vo = new StatisticalRateGroupByTimeVO();
        List<String> time = DateUtils.getTodayDate();
        dto.setStartTime(time.get(0));
        dto.setEndTime(time.get(1));
        List<RealTimeAchievementRateDTO> dayList = workshopCommonMapper.realTimeAchievementRate(dto);
        if (dayList.size() > 0) {
            double daySum = dayList.stream().map(RealTimeAchievementRateDTO::getOutputArea).mapToDouble(Double::valueOf).sum();
            double dayTarget = Double.parseDouble(dayList.get(0).getDayGoal());
            if (dayTarget == 0) {
                vo.setDayRate("0");
                vo.setShiftRate("0");
            } else {
                vo.setDayRate(String.format("%.2f", daySum * 100 / dayTarget));
                vo.setShiftRate(vo.getDayRate());
            }
        } else {
            vo.setDayRate("0");
        }
        vo.setShiftRate(vo.getDayRate());
        time = DateUtils.getCurrentWeek();
        dto.setStartTime(time.get(0));
        dto.setEndTime(time.get(1));
        List<RealTimeAchievementRateDTO> weekList = workshopCommonMapper.realTimeAchievementRate(dto);
        if (weekList.size() > 0) {
            double weekSum = weekList.stream().map(RealTimeAchievementRateDTO::getOutputArea).mapToDouble(Double::valueOf).sum();
            double weekTarget = Double.parseDouble(weekList.get(0).getDayGoal());
            if (weekTarget == 0) {
                vo.setWeekRate("0");
            } else {
                vo.setWeekRate(String.format("%.2f", weekSum * 100 / (weekTarget * 6)));
            }
        } else {
            vo.setWeekRate("0");
        }
        time = DateUtils.getCurrentMonth();
        dto.setStartTime(time.get(0));
        dto.setEndTime(time.get(1));
        List<RealTimeAchievementRateDTO> monthList =  workshopCommonMapper.realTimeAchievementRate(dto);
        if (monthList.size() > 0) {
            double monthSum = monthList.stream().map(RealTimeAchievementRateDTO::getOutputArea).mapToDouble(Double::valueOf).sum();
            double monthTarget = Double.parseDouble(monthList.get(0).getMonthGoal());
            if (monthTarget == 0) {
                vo.setMonthRate("100");
            } else {
                vo.setMonthRate(String.format("%.2f", monthSum * 100 / monthTarget));
            }
        } else {
            vo.setMonthRate("0");
        }
        return vo;
    }

    @DS("wecan")
    @Override
    public BaseHistogramResult waterUnitConsume(CommonQueryDTO dto) {
        BaseHistogramResult result = new BaseHistogramResult();
        List<String> actual = new ArrayList<>();
        List<String> target = new ArrayList<>();
        result.setTarget(target);
        result.setActual(actual);
        List<String> last21Days = DateUtils.getLast21Days();
        result.setXAxis(last21Days);

        ConsumeMeterDataDTO dataDTO = new ConsumeMeterDataDTO();
        BeanUtils.copyProperties(dto, dataDTO);
        dataDTO.setMeterType(ScreenConstants.WATER_METER);

        List<List<String>> rangeList = DateUtils.getLast21DaysRangeList();
        for (List<String> time : rangeList) {
            dataDTO.setStartTime(time.get(0));
            dataDTO.setEndTime(time.get(1));
            Map<String, String> map = this.unitConsume(dataDTO);
            actual.add(map.get("value"));
            target.add(map.get("target"));
        }
        List<String> collect = target.stream().filter(v -> !"0".equals(v)).collect(Collectors.toList());
        if(collect != null && collect.size() > 0){
            String targetStr = collect.get(0);
            for (int i = 0; i < target.size(); i++) {
                if(target.get(i).equals("0")){
                    target.set(i, targetStr);
                }
            }
        }
        return result;
    }

    @DS("wecan")
    @Override
    public BaseHistogramResult electricityUnitConsume(CommonQueryDTO dto) {
        BaseHistogramResult result = new BaseHistogramResult();
        List<String> actual = new ArrayList<>();
        List<String> target = new ArrayList<>();
        result.setTarget(target);
        result.setActual(actual);
        List<String> last21Days = DateUtils.getLast21Days();
        result.setXAxis(last21Days);

        ConsumeMeterDataDTO dataDTO = new ConsumeMeterDataDTO();
        BeanUtils.copyProperties(dto, dataDTO);
        dataDTO.setMeterType(ScreenConstants.ELECTRICITY_METER);

        List<List<String>> rangeList = DateUtils.getLast21DaysRangeList();
        for (List<String> time : rangeList) {
            dataDTO.setStartTime(time.get(0));
            dataDTO.setEndTime(time.get(1));
            Map<String, String> map = this.unitConsume(dataDTO);
            actual.add(map.get("value"));
            target.add(map.get("target"));
        }
        List<String> collect = target.stream().filter(v -> !"0".equals(v)).collect(Collectors.toList());
        if(collect != null && collect.size() > 0){
            String targetStr = collect.get(0);
            for (int i = 0; i < target.size(); i++) {
                if(target.get(i).equals("0")){
                    target.set(i, targetStr);
                }
            }
        }
        return result;
    }

    @DS("wecan")
    @Override
    public Map<String, String> unitConsume(ConsumeMeterDataDTO dataDTO){
        Map<String, String> map = new HashMap<>();
        map.put("target", "0");
        map.put("value", "0");
        CommonQueryDTO dto = new CommonQueryDTO();
        BeanUtils.copyProperties(dataDTO, dto);
        List<ConsumeDetailsVO> vos = this.consumeDetailsByDateType(dto);
        if(vos.size() <= 0) return map;
        String targetData;
        if(ScreenConstants.ELECTRICITY_METER.equals(dataDTO.getMeterType())){
            targetData = vos.get(0).getElectricityTarget();
        } else {
            targetData = vos.get(0).getWaterTarget();
        }
        map.put("target", targetData);
        // 获取当前读数
        List<ConsumeMeterDataVO> dataVOS = this.getConsumeMeterData(dataDTO);
        double latestReading = 0;
        if (dataVOS.size() > 0) {
            latestReading = dataVOS.get(0).getReading();
            latestReading = latestReading > 0 ? latestReading : 0;
            List<String> pastTime = DateUtils.getPastTimeByTime(dataDTO.getStartTime());
            // 获取历史最高读数
            dataDTO.setStartTime(pastTime.get(0));
            dataDTO.setEndTime(pastTime.get(1));
            double originalReading = 0;
            List<ConsumeMeterDataVO> originalVOS = this.getConsumeMeterData(dataDTO);
            if (originalVOS.size() > 0) {
                originalReading = originalVOS.get(0).getReading();
                originalReading = originalReading > 0 ? originalReading : 0;
            }
            double use = latestReading - originalReading;
            map.put("value", String.format("%.2f", use / vos.stream().map(ConsumeDetailsVO::getProduceArea).mapToDouble(Double::valueOf).sum()));
        }
        return map;
    }

    @DS("wecan")
    @Override
    public Map<String, String> totalConsume(ConsumeMeterDataDTO dataDTO){
        Map<String, String> map = new HashMap<>();
        map.put("target", "0");
        map.put("value", "0");
        CommonQueryDTO dto = new CommonQueryDTO();
        BeanUtils.copyProperties(dataDTO, dto);
        List<ConsumeDetailsVO> vos = this.consumeDetailsByDateType(dto);
        if(vos.size() <= 0) return map;
        String targetData;
        if(ScreenConstants.ELECTRICITY_METER.equals(dataDTO.getMeterType())){
            targetData = vos.get(0).getElectricityTarget();
        } else {
            targetData = vos.get(0).getWaterTarget();
        }
        map.put("target", targetData);
        // 获取当前读数
        List<ConsumeMeterDataVO> dataVOS = this.getConsumeMeterData(dataDTO);
        double latestReading = 0;
        if (dataVOS.size() > 0) {
            latestReading = dataVOS.get(0).getReading();
            latestReading = latestReading > 0 ? latestReading : 0;
            List<String> pastTime = DateUtils.getPastTimeByTime(dataDTO.getStartTime());
            // 获取历史最高读数
            dataDTO.setStartTime(pastTime.get(0));
            dataDTO.setEndTime(pastTime.get(1));
            double originalReading = 0;
            List<ConsumeMeterDataVO> originalVOS = this.getConsumeMeterData(dataDTO);
            if (originalVOS.size() > 0) {
                originalReading = originalVOS.get(0).getReading();
                originalReading = originalReading > 0 ? originalReading : 0;
            }
            map.put("value", String.format("%.2f", latestReading - originalReading));
        }
        return map;
    }

    @DS("wecan")
    @Override
    public List<ProductionScheduleVO> productionSchedule(CommonQueryDTO dto) {
        List<String> time = DateUtils.getLast100DaysRange();
        dto.setStartTime(time.get(0));
        dto.setEndTime(time.get(1));
        List<ProductionScheduleVO> vos = workshopCommonMapper.productionSchedule(dto);
        return vos;
    }

    @DS("wecan")
    @Override
    public BaseHistogramResult turnoverRate(CommonQueryDTO dto) {
        StatisticalRateGroupByTimeVO vo = new StatisticalRateGroupByTimeVO();
        List<String> time = DateUtils.getTodayDate();
        dto.setStartTime(time.get(0));
        dto.setEndTime(time.get(1));
        List<RealTimeAchievementRateDTO> dayList = workshopCommonMapper.realTimeAchievementRate(dto);
        if (dayList.size() > 0) {
            double daySum = dayList.stream().map(RealTimeAchievementRateDTO::getOutputArea).mapToDouble(Double::valueOf).sum();
            double dayTarget = Double.parseDouble(dayList.get(0).getDayGoal());
            vo.setShiftTarget(String.format("%.2f", dayTarget / 2));
            vo.setShiftActual(String.format("%.2f", daySum / 2));
            vo.setDayTarget(String.format("%.2f", dayTarget));
            vo.setDayActual(String.format("%.2f", daySum));
        } else {
            vo.setShiftTarget("0");
            vo.setShiftActual("0");
            vo.setDayTarget("0");
            vo.setDayActual("0");
        }
        time = DateUtils.getCurrentWeek();
        dto.setStartTime(time.get(0));
        dto.setEndTime(time.get(1));
        List<RealTimeAchievementRateDTO> weekList = workshopCommonMapper.realTimeAchievementRate(dto);
        if (weekList.size() > 0) {
            double weekSum = weekList.stream().map(RealTimeAchievementRateDTO::getOutputArea).mapToDouble(Double::valueOf).sum();
            double weekTarget = Double.parseDouble(weekList.get(0).getDayGoal());
            vo.setWeekTarget(String.format("%.2f", weekTarget * 6));
            vo.setDayTarget(String.format("%.2f", weekTarget));
            vo.setWeekActual(String.format("%.2f", weekSum));
        } else {
            vo.setWeekTarget("0");
            vo.setWeekActual("0");
        }
        time = DateUtils.getCurrentMonth();
        dto.setStartTime(time.get(0));
        dto.setEndTime(time.get(1));
        List<RealTimeAchievementRateDTO> monthList =  workshopCommonMapper.realTimeAchievementRate(dto);
        if (monthList.size() > 0) {
            double monthSum = monthList.stream().map(RealTimeAchievementRateDTO::getOutputArea).mapToDouble(Double::valueOf).sum();
            double monthTarget = Double.parseDouble(monthList.get(0).getMonthGoal());
            double dayTarget = Double.parseDouble(monthList.get(0).getDayGoal());
            vo.setMonthTarget(String.format("%.2f", monthTarget));
            vo.setDayTarget(String.format("%.2f", dayTarget));
            vo.setMonthActual(String.format("%.2f", monthSum));
        } else {
            vo.setMonthTarget("0");
            vo.setMonthActual("0");
        }
        vo.setShiftTarget(String.format("%.2f", Double.parseDouble(vo.getDayTarget()) / 2));
        BaseHistogramResult result = new BaseHistogramResult();
        List<String> xAxis = Arrays.asList("本月", "本周", "本日", "本班");
        result.setXAxis(xAxis);
        List<String> target = Arrays.asList(vo.getMonthTarget(), vo.getWeekTarget(), vo.getDayTarget(), vo.getShiftTarget());
        result.setTarget(target);
        List<String> actual = Arrays.asList(vo.getMonthActual(), vo.getWeekActual(), vo.getDayActual(), vo.getShiftActual());
        result.setActual(actual);
        return result;
    }

    @DS("wecan")
    @Override
    public StatisticalRateGroupByTimeVO turnoverRateGroupByTimeType(CommonQueryDTO dto) {
        return achievementRateGroupByTimeType(dto);
    }

    @Override
    public RealTimeAchievementRateVO samplingPassRate() {
        return null;
    }

    @Override
    public SamplingPassRateTrendVO samplingPassRateTrend() {
        return null;
    }

    @Override
    public List<BasePieChartResult> samplingBadStatistics() {
        return null;
    }

    @Override
    public RealTimeAchievementRateVO inspectionPassRate() {
        return null;
    }

    @Override
    public BaseHistogramResult inspectionPassRateTrend() {
        return null;
    }

    @Override
    public List<BasePieChartResult> inspectionBadStatistics() {
        return null;
    }

    @Override
    public RealTimeAchievementRateVO PCS_scrapPassRate() {
        return null;
    }

    @Override
    public List<BasePieChartResult> PCS_scrapStatistics() {
        return null;
    }

    @DS("wecan")
    @Override
    public List<PassRateRecordVO> passRateRecord(CommonQueryDTO dto) {
        List<String> time = DateUtils.getLast30DaysRange();
        dto.setStartTime(time.get(0));
        dto.setEndTime(time.get(1));
        return workshopCommonMapper.passRateRecord(dto);
    }

    @DS("wecan")
    @Override
    public List<BasePieChartResult> badStatistics(CommonQueryDTO dto) {
        if(dto.getStartTime() == null) {
            List<String> time = DateUtils.getLast30DaysRange();
            dto.setStartTime(time.get(0));
            dto.setEndTime(time.get(1));
        }
        List<BasePieChartResult> resultList = workshopCommonMapper.badStatistics(dto);
        return getBasePieChartResults(resultList);
    }

    @DS("wecan")
    @Override
    public List<BasePieChartResult> scrapStatistics(CommonQueryDTO dto) {
        if(dto.getStartTime() == null) {
            List<String> time = DateUtils.getLast30DaysRange();
            dto.setStartTime(time.get(0));
            dto.setEndTime(time.get(1));
        }
        List<BasePieChartResult> resultList = workshopCommonMapper.scrapStatistics(dto);
        return getBasePieChartResults(resultList);
    }

    @DS("wecan")
    @Override
    public PassRateVO passRate(CommonQueryDTO dto) {
        List<String> todayDate = DateUtils.getTodayDate();
        dto.setStartTime(todayDate.get(0));
        dto.setEndTime(todayDate.get(1));
        PassRateVO todayVo = workshopCommonMapper.passRate(dto);
        if (todayVo == null) {
            todayVo = new PassRateVO();
            todayVo.setDefectNum("0");
        }
        List<String> currentMonth = DateUtils.getCurrentMonth();
        dto.setStartTime(currentMonth.get(0));
        dto.setEndTime(currentMonth.get(1));
        PassRateVO monthVo = workshopCommonMapper.passRate(dto);
        if (monthVo == null) {
            monthVo = new PassRateVO();
            monthVo.setInspectNum("0");
            monthVo.setPassNum("0");
            monthVo.setDefectNum("0");
            monthVo.setDefectRate("0");
        }
        monthVo.setDefectNum(todayVo.getDefectNum());
        monthVo.setDefectRate(String.format("%.2f", Double.parseDouble(monthVo.getDefectRate())));
        return monthVo;
    }
    @DS("wecan")
    @Override
    public ScrapRateVO scrapRate(CommonQueryDTO dto) {
        List<String> todayDate = DateUtils.getTodayDate();
        dto.setStartTime(todayDate.get(0));
        dto.setEndTime(todayDate.get(1));
        ScrapRateVO todayVo = workshopCommonMapper.scrapRate(dto);
        if (todayVo == null) {
            todayVo = new ScrapRateVO();
            todayVo.setOutputNum("0");
            todayVo.setOutputArea("0");
            todayVo.setScrapNum("0");
            todayVo.setScrapRate("0");
            todayVo.setScrapArea("0");
        }

        List<String> currentMonth = DateUtils.getCurrentMonth();
        dto.setStartTime(currentMonth.get(0));
        dto.setEndTime(currentMonth.get(1));
        ScrapRateVO monthVo = workshopCommonMapper.scrapRate(dto);
        if (monthVo == null) {
            monthVo = new ScrapRateVO();
            monthVo.setOutputNum("0");
            monthVo.setOutputArea("0");
            monthVo.setScrapNum("0");
            monthVo.setScrapRate("0");
            monthVo.setScrapArea("0");
        }
        monthVo.setDay(todayVo);
        return monthVo;
    }

    @DS("wecan")
    @Override
    public BaseHistogramResult passRateTrend(CommonQueryDTO dto) {
        List<String> time = DateUtils.getLast21DaysRange();
        dto.setStartTime(time.get(0));
        dto.setEndTime(time.get(1));
        List<HistogramDto> dtoList = workshopCommonMapper.passRateTrend(dto);
        BaseHistogramResult result = new BaseHistogramResult();
        List<String> last21Days = DateUtils.getLast21Days();
        result.setXAxis(last21Days);
        List<String> target = new ArrayList<>();
        List<String> actual = new ArrayList<>();
        result.setTarget(target);
        result.setActual(actual);
        for (String day : last21Days) {
            target.add("100");
            String actualStr = "100";
            for (HistogramDto histogramDto : dtoList) {
                if (DateUtils.parseDateToStr(DateUtils.MM_DD, DateUtils.parseDate(histogramDto.getXAxis())).equals(day)){
                    actualStr = histogramDto.getActual();
                    break;
                }
            }
            actual.add(actualStr);
        }

        return result;
    }


    public List<BasePieChartResult> getBasePieChartResults(List<BasePieChartResult> resultList) {
        if (resultList == null || resultList.size() == 0) {
            return null;
        }
        List<BasePieChartResult> results = new ArrayList<>();
        int other = 0;
        for (int i = 0; i < resultList.size(); i++) {
            BasePieChartResult basePieChartResult = resultList.get(i);
            if(i > 4 || "其他".equals(basePieChartResult.getType().trim())){
                other += Double.parseDouble(basePieChartResult.getValue());
            } else {
                results.add(basePieChartResult);
            }
        }
        if (other > 0) {
            BasePieChartResult basePieChartResult = new BasePieChartResult();
            basePieChartResult.setType("其他");
            basePieChartResult.setValue(other + "");
            results.add(basePieChartResult);
        }
        return results;
    }

    @DS("wecan")
    @Override
    public List<ConsumeDetailsVO> consumeDetailsByDateType(CommonQueryDTO dto) {

        return workshopCommonMapper.consumeDetailsByDateType(dto);
    }

    @DS("wecan")
    @Override
    public List<ConsumeMeterDataVO> getConsumeMeterData(ConsumeMeterDataDTO dto) {
        return workshopCommonMapper.getConsumeMeterData(dto);
    }

}